import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

var router = new Router({
    //'mode': 'history', //去掉URL的#号，需要配置服务器http://router.vuejs.org/zh-cn/essentials/history-mode.html
    //'linkActiveClass': 'active',
    scrollBehavior (to, from, savedPosition) {
        if (savedPosition) {
          return savedPosition
        } else {
          return { x: 0, y: 0 }
        }
    },
    routes: [
        // {
        //     path: '*',
        //     redirect: '/home'
        // },
        {
            path: '/',
            redirect: '/home'
        },
        {
            path: '/home',
            component: resolve => require(['_views/index/Home/Home.vue'], resolve),
            meta: { 
                title: '首页',
                keepAlive: true
            }
        }
    ]
})
router.beforeEach((to, from, next) => {
    if(!to.meta.title){
        document.title = to.query.title;
    }else{
        document.title = to.meta.title;
    }
    next();
})
export default router;